package com.hisoft.entity;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;
/**
 * 临时变量
 * @author JohnTest
 *
 */
public class VariableMap {
	static Logger logger = Logger.getLogger(VariableMap.class);
	private Map<String, String> map = new HashMap<String, String>();
	// 单例模式
	private static VariableMap variableMap = null;

	private VariableMap() {
	}

	// singleton
	public synchronized static VariableMap getInstance() {
		if (null == variableMap) {
			logger.info("initializing VariableMap ...");
			variableMap = new VariableMap();
		}
		return variableMap;
	}

	public boolean mapPutKV(String key, String value) {
		logger.debug("map.put( " + key + " , " + value + " )");
		try {
			map.put(key, value);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return false;
		}
		return true;
	}

	public boolean mapPutKV(String key, Number value) {
		logger.debug("map.put( " + key + " , " + value + " )");
		try {
			map.put(key, "" + value);
		} catch (Exception e) {
			logger.error(e.getMessage());
			return false;
		}
		return true;
	}

	public String mapGetValue(String key) {
		if (map.containsKey(key)) {
			return map.get(key);
		} else {
			logger.info("map does not contain key '" + key + "', return ''.");
			return "";
		}
	}

}
